window.onload = function () {

    var message = [
        '  _  _   __  __   _  _   \n' +
        ' | || |  \\ \\/ /  | || |  \n' +
        ' | __ |   >  <   | __ |  \n' +
        ' |_||_|  /_/\\_\\  |_||_|  \n' +
        '_|"""""|_|"""""|_|"""""| \n' +
        '"`-0-0-\'"`-0-0-\'"`-0-0-\' '].join('/n');

    function Time(time) {
        //输入时间
        var newTime = new Date(time);
        //现在时间
        var sj = (Date.now() - newTime.getTime()) / 1000;

        //天
        var a = sj / 60 / 60 / 24;
        a = a < 10 ? '0' + a : a;
        var b = sj / 60 / 60 % 24;
        //小时
        b = b < 10 ? '0' + b : b;
        //分
        var c = sj / 60 % 60;
        c = c < 10 ? '0' + c : c;
        //秒
        var d = sj % 60;
        d = d < 10 ? '0' + d : d;
        return parseInt(a) + '天' + parseInt(b) + '时' + parseInt(c) + '分' + parseInt(d) + '秒';
    }

    var str = message + '\n欢迎访问潇涵起始页';
    var color = "#3c6cfb";
    var colorTime = '#07ff11';
    var time = '起始页已上线' + Time('2020-10-01 20:35:00');
    console.log('%c ' + str, 'color: ' + color);
    console.log('%c ' + time, 'color:' + colorTime);


    //用户窗口高度
    var UserclientHeight = document.documentElement.clientHeight;

    //背景图片
    var imgs = document.getElementById('imgbg');
    //存储cookie
    var storage = window.localStorage;


    //确定图片的div
    var right = document.getElementsByClassName('right');
    //默认存储
    if (storage['bgPreference'] == null && storage['a'] == null && storage['rightIndex'] == null) {
        storage['rightIndex'] = 2;
        storage['a'] = 1;
        right[storage.rightIndex].style.display = 'block';
        storage['bgPreference'] = '/images/3aa3b1a332986b5744d7bbb4a82cab443cd71a1c.jpg';
    }
    if (storage.a == 1) {
        right[storage.rightIndex].style.display = 'block';
        imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
        imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
        imgs.style.backgroundPositionX = 'center';
        imgs.style.backgroundPositionY = '0';
    }
    if (storage.a == 2) {
        videobg.src = storage.bgPreference;
        imgs.style.opacity = 0;
        videobg.style.opacity = 1;
    }
    if (storage.a == 3) {
        for (var k = 0; k < right.length; k++) {
            right[k].style.display = 'none';
            right[k].style.zIndex = 0;
        }
        imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
        imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
        imgs.style.backgroundPositionX = 'center';
        imgs.style.backgroundPositionY = '0';
    }

    var dayImgUlA = document.getElementsByClassName('dayImgUlA');

    function updateImg() {
        imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
        imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
        imgs.style.backgroundPositionX = 'center';
        imgs.style.backgroundPositionY = '0';
    }

    //唯美
    function Beautiful() {
        $.post("/img/parseBaiDu", {queryWord: "唯美"}, function (data) {
            if (data == null || data == '') {
                storage['bgPreference'] = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3136626573,2216251976&fm=26&gp=0.jpg";
                if (storage.a == 1) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                }
                if (storage.a == 2) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                    imgs.style.opacity = 1;
                    videobg.style.opacity = 0;
                }

            } else {
                storage['bgPreference'] = data;
                imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                imgs.style.backgroundPositionX = 'center';
                imgs.style.backgroundPositionY = '0';
                imgs.style.opacity = 1;
                videobg.style.opacity = 0;
            }
            setTimeout(updateImg, 2000);

        })
    }


    //可爱
    function Cute() {
        $.post("/img/parseBaiDu", {queryWord: "可爱"}, function (data) {
            if (data == null || data == '') {
                storage['bgPreference'] = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3136626573,2216251976&fm=26&gp=0.jpg";
                if (storage.a == 1) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                }
                if (storage.a == 2) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                    imgs.style.opacity = 1;
                    videobg.style.opacity = 0;
                }

            } else {
                storage['bgPreference'] = data;
                imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                imgs.style.backgroundPositionX = 'center';
                imgs.style.backgroundPositionY = '0';
                imgs.style.opacity = 1;
                videobg.style.opacity = 0;
            }
            setTimeout(updateImg, 2000);


        })
    }

    //萌宠
    function Pets() {
        $.post("/img/parseBaiDu", {queryWord: "动物"}, function (data) {
            if (data == null || data == '') {
                storage['bgPreference'] = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3136626573,2216251976&fm=26&gp=0.jpg";
                if (storage.a == 1) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                }
                if (storage.a == 2) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                    imgs.style.opacity = 1;
                    videobg.style.opacity = 0;
                }

            } else {
                storage['bgPreference'] = data;
                imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                imgs.style.backgroundPositionX = 'center';
                imgs.style.backgroundPositionY = '0';
                imgs.style.opacity = 1;
                videobg.style.opacity = 0;
            }
            setTimeout(updateImg, 2000);

        })
    }

    // 简约
    function simple() {
        $.post("/img/parseBaiDu", {queryWord: "简约"}, function (data) {
            if (data == null || data == '') {
                storage['bgPreference'] = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3136626573,2216251976&fm=26&gp=0.jpg";
                if (storage.a == 1) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                }
                if (storage.a == 2) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                    imgs.style.opacity = 1;
                    videobg.style.opacity = 0;
                }

            } else {
                storage['bgPreference'] = data;
                imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                imgs.style.backgroundPositionX = 'center';
                imgs.style.backgroundPositionY = '0';
                imgs.style.opacity = 1;
                videobg.style.opacity = 0;
            }
            setTimeout(updateImg, 2000);


        })
    }

    // 壁纸
    function wallpaper() {
        $.post("/img/parseBaiDu", {queryWord: "风景"}, function (data) {
            if (data == null || data == '') {
                storage['bgPreference'] = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3136626573,2216251976&fm=26&gp=0.jpg";
                if (storage.a == 1) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                }
                if (storage.a == 2) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                    imgs.style.opacity = 1;
                    videobg.style.opacity = 0;
                }

            } else {
                storage['bgPreference'] = data;
                imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                imgs.style.backgroundPositionX = 'center';
                imgs.style.backgroundPositionY = '0';
                imgs.style.opacity = 1;
                videobg.style.opacity = 0;
            }
            setTimeout(updateImg, 2000);

        })
    }

    // 二次元
    function quadratic() {
        $.post("/img/parseBaiDu", {queryWord: "动漫"}, function (data) {
            if (data == null || data == '') {
                storage['bgPreference'] = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3136626573,2216251976&fm=26&gp=0.jpg";
                if (storage.a == 1) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                }
                if (storage.a == 2) {
                    imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                    imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                    imgs.style.backgroundPositionX = 'center';
                    imgs.style.backgroundPositionY = '0';
                    imgs.style.opacity = 1;
                    videobg.style.opacity = 0;
                }

            } else {
                storage['bgPreference'] = data;
                imgs.style.background = 'url(' + storage.bgPreference + ') no-repeat';
                imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
                imgs.style.backgroundPositionX = 'center';
                imgs.style.backgroundPositionY = '0';
                imgs.style.opacity = 1;
                videobg.style.opacity = 0;
            }
            setTimeout(updateImg, 2000);

        })
    }


    function dayImgRight() {
        for (var k = 0; k < right.length; k++) {
            right[k].style.display = 'none';
            right[k].style.zIndex = 0;
        }
    }

    //3代表每日图片
    dayImgUlA[0].addEventListener('click', function () {
        storage['a'] = 3;
        dayImgRight();
        Beautiful();
    });
    dayImgUlA[1].addEventListener('click', function () {
        storage['a'] = 3;
        dayImgRight();
        Cute();
    });
    dayImgUlA[2].addEventListener('click', function () {
        storage['a'] = 3;
        dayImgRight();
        Pets();
    });
    dayImgUlA[3].addEventListener('click', function () {
        storage['a'] = 3;
        dayImgRight();
        simple();
    });
    dayImgUlA[4].addEventListener('click', function () {
        storage['a'] = 3;
        dayImgRight();
        wallpaper();
    });
    dayImgUlA[5].addEventListener('click', function () {
        storage['a'] = 3;
        dayImgRight();
        quadratic();
    });

    //选择图片更改背景
    var bjimg = document.getElementsByClassName('bjimg');


    var bjvideo = document.getElementsByClassName('bjvideo');

    for (var i = 0; i < bjvideo.length; i++) {
        bjvideo[i].onclick = function () {
            for (var k = 0; k < right.length; k++) {
                right[k].style.display = 'none';
                right[k].style.zIndex = 0;
            }
            for (var j = 0; j < bjvideo.length; j++) {
                if (this == bjvideo[j]) {
                    right[j + bjimg.length].style.display = 'block';
                    right[j + bjimg.length].style.zIndex = 99;
                    storage['bgPreference'] = this.src;
                    storage['rightIndex'] = j + bjimg.length;
                    //2代表动态
                    storage['a'] = 2;
                }
            }
            videobg.src = this.src;
            imgs.style.opacity = 0;
            videobg.style.opacity = 1;
        }
    }


    for (var i = 0; i < bjimg.length; i++) {
        bjimg[i].onclick = function () {
            for (var k = 0; k < right.length; k++) {
                right[k].style.display = 'none';
                right[k].style.zIndex = 0;
            }
            imgs.style.background = 'url(' + this.src + ') no-repeat';
            for (var j = 0; j < bjimg.length; j++) {
                if (this == bjimg[j]) {
                    right[j].style.display = 'block';
                    right[j].style.zIndex = 99;
                    storage['bgPreference'] = this.src;
                    storage['rightIndex'] = j;
                    //1代表普通壁纸
                    storage['a'] = 1;
                }

            }
            imgs.style.backgroundSize = '100% ' + UserclientHeight + 'px';
            imgs.style.backgroundPositionX = 'center';
            imgs.style.backgroundPositionY = '0';
            imgs.style.opacity = 1;
            videobg.style.opacity = 0;
        }
    }

    //设置按钮
    var setting = document.getElementById('setting');

    //设置菜单
    var setmenu = document.getElementById('setmenu');
    //设置菜单的背景设置
    var imgsettingLi = document.getElementById('imgsettingLi');

    var colse = document.getElementById('colse');

    //背景设置页面
    var imgsetting = document.getElementById('imgsetting');
    //关闭关于我
    var colseAboutMe = document.getElementById('colseAboutMe');
    //关于我页面
    var aboutMe = document.getElementById('aboutMe');
    //关于我按钮
    var menuAboutMe = document.getElementById('menuAboutMe');


    var menuAboutMeInterval;
    menuAboutMe.onclick = function () {
        //壁纸
        imgbg.style.filter = 'blur(1.3px)';
        imgbg.style.transform = 'scale(1.1)';
        cover.style.opacity = 1;
        cover.style.zIndex = 99;
        aboutMe.style.display = 'block';
        aboutMe.style.zIndex = '9999';

        //动态壁纸
        videobg.style.filter = 'blur(1.3px)';
        videobg.style.transform = 'scale(1.1)';
        clearInterval(menuAboutMeInterval);
        var i = 0;
        menuAboutMeInterval = setInterval(function () {
            aboutMe.style.opacity = i;
            i = i + 0.1;
            if (i > 1) {
                aboutMe.style.display = 'block';
                clearInterval(menuAboutMeInterval);
            }
        }, 20);

    };

    colseAboutMe.onclick = function () {
        //壁纸
        imgbg.style.filter = 'blur(0px)';
        imgbg.style.transform = 'scale(1)';
        //动态壁纸
        videobg.style.filter = 'blur(0px)';
        videobg.style.transform = 'scale(1)';
        cover.style.opacity = 0;
        cover.style.zIndex = 0;
        clearInterval(menuAboutMeInterval);
        var i = 1;
        menuAboutMeInterval = setInterval(function () {
            aboutMe.style.opacity = i;
            i = i - 0.1;
            if (i < 0) {
                aboutMe.style.zIndex = '0';
                aboutMe.style.display = 'none';
                clearInterval(menuAboutMeInterval);
            }
        }, 20);
    };

    colse.onmouseenter = function () {
        this.style.transform = 'scale(1.2)';
        this.style.transition = 'all .55s ease-in-out';
        this.style.color = '#1d39ff';
        imgsetting.style.transition = 'all .35s ease-in-out';
        imgsetting.style.transform = 'rotateX(20deg) rotateY(15deg) translate(-50%, -50%)';

    };
    colse.onmouseleave = function () {
        this.style.transform = 'scale(1)';
        this.style.color = 'black';
        imgsetting.style.transition = 'all .55s ease-in-out';
        imgsetting.style.transform = 'rotate(0deg) translate(-50%, -50%)';

    };

    //关闭背景设置页面
    colse.onclick = function () {
        //壁纸
        imgbg.style.filter = 'blur(0px)';
        imgbg.style.transform = 'scale(1)';
        //动态壁纸
        videobg.style.filter = 'blur(0px)';
        videobg.style.transform = 'scale(1)';
        imgsetting.style.zIndex = '0';
        imgsetting.style.display = 'none';
        cover.style.opacity = 0;
        cover.style.zIndex = 0;
    };

    imgsettingLi.onclick = function () {
        //壁纸
        imgbg.style.filter = 'blur(1.3px)';
        imgbg.style.transform = 'scale(1.1)';
        cover.style.opacity = 1;
        cover.style.zIndex = 99;
        //动态壁纸
        videobg.style.filter = 'blur(1.3px)';
        videobg.style.transform = 'scale(1.1)';
        imgsetting.style.zIndex = '9999';
        imgsetting.style.display = 'block';
    };

    var setmenuInterval;
    setmenu.onmouseover = function () {
        clearInterval(setmenuInterval);
        this.style.transition = 'all .5s ease-in-out';
        this.style.transform = 'scaleY(1.05)';
        setmenu.style.zIndex = 9999;
        setmenu.style.display = 'block';
        setmenu.style.opacity = 1;
    };
    setmenu.onmouseout = function () {
        this.style.transform = 'scaleY(1)';
        var i = 1;
        clearInterval(setmenuInterval);
        setmenuInterval = setInterval(function () {
            setmenu.style.opacity = i;
            i = i - 0.1;
            if (i < 0) {
                setmenu.style.zIndex = 0;
                setmenu.style.display = 'none';
                clearInterval(setmenuInterval);
            }
        }, 25);

    };
    setting.onmouseout = function () {
        var i = 1;
        clearInterval(setmenuInterval);
        setmenuInterval = setInterval(function () {
            setmenu.style.opacity = i;
            i = i - 0.1;
            if (i < 0) {
                setmenu.style.zIndex = 0;
                setmenu.style.display = 'none';
                clearInterval(setmenuInterval);
            }
        }, 25);
    };

    setting.onmouseover = function () {
        setmenu.style.zIndex = 9999;
        setmenu.style.display = 'block';
        setmenu.style.opacity = 1;

    };
    /*
    0关闭 1打开
    点击关闭开启功能
    var menufalg = 1;
    setting.onclick = function() {
        if (menufalg == 1) {
            setmenu.style.zIndex = 999;
            menufalg = 0;
            return;
        }
        if (menufalg == 0) {
            menufalg = 1;
            setmenu.style.zIndex = 0;
            return;
        }
    } */


};

//存储cookie
var hint = window.localStorage;
var msg = document.getElementById('msg');

if (hint['hint'] == null) {
    msg.style.display = 'block';
    msg.style.opacity = 1;
} else {
    msg.style.display = 'none';
    msg.style.opacity = 0;
}

//获取结果集对象
var li = document.getElementsByClassName('resultSearchLi');
var inputSearch = document.getElementById('inputSearch');
var inputSearchvalue;
var totalStr = '';
inputSearch.addEventListener('keyup', function (e) {
    ptag[0].style.visibility = 'hidden';
    ptag[1].style.visibility = 'hidden';
    tag.style.visibility = 'hidden';
    inputSearchvalue = inputSearch.value;
    window.removeEventListener('keydown', windowEventListener);
    if (inputSearchvalue.length > 0) {
        $.post("/parseBaiDu", {wd: inputSearchvalue}, function (data) {
            var str = '';
            var astr = '';
            if (data.length == 0) {
                totalStr = '<a target="_blank" style="border-radius: 25px" href="https://fanyi.baidu.com/#en/zh/' + inputSearchvalue + '" class="resultSearchLi">翻译:' + inputSearchvalue + '</a>';
                ;
            } else if (data.length > 0) {
                var translate = '<a target="_blank" href="https://fanyi.baidu.com/#en/zh/' + inputSearchvalue + '" class="resultSearchLi" style="border-top-right-radius: 10px;border-top-left-radius: 10px;">翻译:' + inputSearchvalue + '</a>';
                for (var i = 0; i < data.length; i++) {
                    if (i == data.length - 1) {
                        astr = '<a target="_blank" style="border-bottom-left-radius: 10px;border-bottom-right-radius: 10px;" href="https://www.baidu.com/s?wd=' + data[i].q + '" class="resultSearchLi">' + data[i].q + '</a>';
                    } else {
                        astr = '<a target="_blank" href="https://www.baidu.com/s?wd=' + data[i].q + '" class="resultSearchLi">' + data[i].q + '</a>';
                    }
                    str += astr;
                }
                totalStr = translate + str;
            }
            $("#resultSearchUl").html(totalStr);
        });
    } else {
        $("#resultSearchUl").html('');
    }


    if (e.keyCode == 13) {
        location.href = 'https://www.baidu.com/s?wd=' + inputSearch.value; // s代表搜索，wd代表word
    }


});

var inputSearch = document.getElementById('inputSearch');
var resultSearchUl = document.getElementById('resultSearchUl');


var windowEventListener = function (e) {
    if (e.keyCode) {
        ptag[0].style.visibility = 'visible';
        imgbg.style.filter = 'blur(1.3px)';
        imgbg.style.transform = 'scale(1.1)';
        cover.style.opacity = 1;
        inputSearch.style.width = '500px';
        inputSearch.style.color = 'rgba(0, 0, 0, 0.8)';
        inputSearch.removeEventListener('mouseleave', aa);
        inputSearch.focus();
    }
};
window.addEventListener('keydown', windowEventListener);

window.onkeydown = function (e) {
    if (e.keyCode == 9) {
        if (e.preventDefault) {
            e.preventDefault();
        } else {
            e.returnValue = false;
        }
    }
};


//禁止打开菜单鼠标事件
document.addEventListener('contextmenu', function (e) {
    e.preventDefault();

});

var time = document.getElementById('time');

var inputSearch = document.getElementById('inputSearch');
var imgbg = document.getElementById('imgbg');

var videobg = document.getElementById('videobg');


var cover = document.getElementById('cover');
var tag = document.getElementById('tag');
var ptag = document.getElementsByClassName('ptag');

var navboxCustom = document.getElementById('navboxCustom');

//1代表打开链接列表、0表示打开搜索
var timeFlag = 1;

var writerBoxInterval;
cover.onclick = coverFuntion;

function coverFuntion() {
    menuCusNav.style.opacity = 0;
    menuCusNav.style.display = 'none';
    //关闭关于我
    aboutMe.style.zIndex = '0';
    aboutMe.style.display = 'none';
    //关闭登录页
    login.style.opacity = 0;
    login.style.display = 'none';
    //关闭图片设置页
    imgsetting.style.zIndex = '0';
    imgsetting.style.display = 'none';

    navboxCustom.style.display = 'none';
    //壁纸
    imgbg.style.filter = 'blur(0px)';
    imgbg.style.transform = 'scale(1)';
    addTag.style.display = 'none';
    addTag.style.opacity = 0;
    addLastFlag = 1;
    colseLoginFlag = 0;
    //动态壁纸
    videobg.style.filter = 'blur(0px)';
    videobg.style.transform = 'scale(1)';
    inputSearch.style.display = 'inline-block';
    cover.style.opacity = 0;
    cover.style.zIndex = 0;

    timeFlag = 1;

    //关闭写字板
    setTimeout(function () {

        writerTextareaOnblur();
        var i = 1;

        writerBoxInterval = setInterval(function () {
            writerBox.style.opacity = i;
            writerLi.style.opacity = i;
            i = i - 0.1;
            if (i < 0) {
                writerBox.style.zIndex = 0;
                writerBox.style.display = 'none';
                writerTextareaOnfocus();
                clearInterval(writerBoxInterval);
            }
        }, 35);

    }, 300);


    addEventListener('keydown', windowEventListener);
};
var navboxCustomInterval;

function selectAllLink() {
    $.post('/link/selectAllLink', '', function (data) {
        var str = '';
        var link = '';
        if (data == '') {
            str = '';
        } else {
            for (var i = 0; i < data.length; i++) {
                var ranStr = (Math.random() * data[i].title.length);
                link = '<div class="shouldNotSwitch ContextMenu">\n' +
                    '                <a href="' + data[i].url + '" target="black">\n' +
                    '                    <div style="position: absolute;width: 80px;height: 80px;background: rgba(255, 255, 255, .45);line-height: 80px;overflow:hidden;border-radius: 20px"><span style="display: inline-block;margin-top: 15px;width: 50px;height: 50px;border-radius: 255px;line-height: 50px;background: rgba(0, 0, 0, .45);color: white">' + data[i].title.substring(data[i].title.length / 2, data[i].title.length / 2 + 1) + '</span></div>\n' +
                    '                    <span class="spaniocn">' + data[i].title + '</span>\n' +
                    '                </a>\n' + '<input type="hidden" value="' + data[i].id + '">' +
                    '            </div>';
                str += link;
            }
        }
        $("#userLink").html(str);
        var ContextMenu = document.getElementsByClassName('ContextMenu');
        var menuCusNav = document.getElementById('menuCusNav');
        for (var i = 0; i < ContextMenu.length; i++) {
            ContextMenu[i].oncontextmenu = function (e) {
                menuCusNav.style.opacity = 1;
                menuCusNav.style.display = 'block';
                menuCusNav.style.left = e.pageX + 'px';
                menuCusNav.style.top = e.pageY + 'px';
                var link = this;
                var userMenuItem = document.getElementsByClassName('userMenuItem');
                userMenuItem[1].onclick = function () {
                    $.post('/link/deleteId', {id: link.children[1].value}, function (data) {
                        menuCusNav.style.opacity = 0;
                        menuCusNav.style.display = 'none';
                        selectAllLink();
                    });
                }
            }

        }
        menuCusNav.onmouseleave = function () {
            menuCusNav.style.opacity = 0;
            menuCusNav.style.display = 'none';
        }
    });
};
// var selectAllLinkInterval;
/*navboxCustom.addEventListener('mousemove    ', function (e) {
    this.style.transition = 'all .25s ease-in-out';
    console.log(this.offsetLeft - e.clientX);
    /!*if ((e.clientX - this.offsetLeft) <= (this.offsetWidth / 2) && (e.clientY - this.offsetTop) < (this.offsetHeight / 2)) {
        this.style.transform = 'rotateX(20deg) rotateY(-15deg)';
    }
    if ((e.clientX - this.offsetLeft) <= (this.offsetWidth / 2) && (e.clientY - this.offsetTop) >= (this.offsetHeight / 2)) {
        this.style.transform = 'rotateX(-20deg) rotateY(-15deg)';
    }
    if ((e.clientX - this.offsetLeft) > (this.offsetWidth / 2) && (e.clientY - this.offsetTop) > (this.offsetHeight / 2)) {
        this.style.transform = 'rotateX(-20deg) rotateY(15deg)';
    }
    if ((e.clientX - this.offsetLeft) >= (this.offsetWidth / 2) && (e.clientY - this.offsetTop) <= (this.offsetHeight / 2)) {
        this.style.transform = 'rotateX(20deg) rotateY(15deg)';
    }*!/
});
navboxCustom.addEventListener('mouseleave', function (e) {
    this.style.transition = 'all .25s ease-in-out';
    this.style.transform = 'rotate(0deg)';
});*/
time.addEventListener('click', function () {
    clearInterval(navboxCustomInterval);
    // clearInterval(selectAllLinkInterval);
    //打开链接列表
    if (timeFlag == 1) {
        // clearInterval(selectAllLinkInterval);
        hint.hint = 0;
        msg.style.display = 'none';
        msg.style.opacity = 0;
        //查询所有该用户所有链接
        selectAllLink();
        // selectAllLinkInterval = setInterval(selectAllLink, 500);
        var i = 0;
        navboxCustom.style.display = 'block';
        navboxCustomInterval = setInterval(function () {
            navboxCustom.style.opacity = i;
            i = i + 0.1;
            if (i > 1) {
                clearInterval(navboxCustomInterval);
            }
        }, 20);

        //壁纸
        imgbg.style.filter = 'blur(1.3px)';
        imgbg.style.transform = 'scale(1.1)';
        //动态壁纸
        videobg.style.filter = 'blur(1.3px)';
        videobg.style.transform = 'scale(1.1)';
        inputSearch.style.display = 'none';
        timeFlag = 0;
        cover.style.opacity = 1;
        cover.style.zIndex = 99;
        removeEventListener('keydown', windowEventListener);
        return;
    }
    //关闭链接列表
    if (timeFlag == 0) {
        // clearInterval(selectAllLinkInterval);
        var i = 1;
        navboxCustomInterval = setInterval(function () {
            navboxCustom.style.opacity = i;
            i = i - 0.1;
            if (i < 0) {
                menuCusNav.style.opacity = 0;
                menuCusNav.style.display = 'none';
                navboxCustom.style.display = 'none';
                inputSearch.style.display = 'inline-block';
                clearInterval(navboxCustomInterval);
            }
        }, 20);
        //壁纸
        imgbg.style.filter = 'blur(0px)';
        imgbg.style.transform = 'scale(1)';
        addTag.style.display = 'none';
        addTag.style.opacity = 0;
        addLastFlag = 1;
        //动态壁纸
        videobg.style.filter = 'blur(0px)';
        videobg.style.transform = 'scale(1)';
        cover.style.opacity = 0;
        cover.style.zIndex = 0;
        timeFlag = 1;
        addEventListener('keydown', windowEventListener);
        return;
    }
});


inputSearch.value = 'Search';

inputSearch.addEventListener('mouseenter', function () {
    this.style.width = '500px';
    this.style.color = 'rgba(0, 0, 0, 0.8)';
});

var aa = function () {
    this.style.width = '250px';
    this.style.color = ' rgba(255, 255, 255, 0.9)';
};
inputSearch.addEventListener('mouseleave', aa);

tag.addEventListener('mouseout', function () {
    inputSearch.focus();
    ptag[0].style.visibility = 'visible';
    imgbg.style.filter = 'blur(1.3px)';
    imgbg.style.transform = 'scale(1.1)';
    cover.style.opacity = 1;
    inputSearch.value = '';
    inputSearch.style.width = '500px';
    inputSearch.style.color = 'rgba(0, 0, 0, 0.8)';
    tag.style.background = 'rgba(255, 255, 255, 0.25)';
});

//申明全局变量
var timeStart, timeEnd, mouseDownSetInterval;

//获取此刻时间
function getTimeNow() {
    var now = new Date();
    return now.getTime();
}

tag.addEventListener('mousedown', function () {
    $.get('https://v1.hitokoto.cn/?c=d&c=i&encode=json', '', function (data) {
        console.log(data);
        ptag[0].innerHTML = '「&nbsp;&nbsp;' + data.hitokoto + '」';
        ptag[1].innerHTML = '——' + data.from;
    });
    //获取鼠标按下时的时间
    timeStart = getTimeNow();
    //setInterval会每100毫秒执行一次，也就是每100毫秒获取一次时间
    mouseDownSetInterval = setInterval(function () {
        timeEnd = getTimeNow();
        //字体变红
        tag.style.background = 'linear-gradient(90deg, green, #CD5C5C, pink, #1E90FF)';
        //如果此时检测到的时间与第一次获取的时间差有1000毫秒
        if (timeEnd - timeStart > 1000) {
            console.log(timeEnd);
            console.log(timeStart);
            //便不再继续重复此函数 （clearInterval取消周期性执行）
            clearInterval(mouseDownSetInterval);
        }
    }, 100);

});

tag.addEventListener('mouseup', function () {
    clearInterval(mouseDownSetInterval);
    tag.style.background = 'none';
    tag.style.background = 'rgba(255, 255, 255, .25)';
});

tag.addEventListener('mouseleave', function () {
    ptag[1].style.visibility = 'hidden';
    tag.style.visibility = 'hidden';
});

tag.addEventListener('mouseenter', function () {
    ptag[1].style.visibility = 'visible';
    tag.style.visibility = 'visible';


});

//获取焦点
inputSearch.addEventListener('focus', function () {
    ptag[0].style.visibility = 'visible';
    //壁纸
    imgbg.style.filter = 'blur(1.3px)';
    imgbg.style.transform = 'scale(1.1)';

    cover.style.zIndex = 99;

    //动态壁纸
    videobg.style.filter = 'blur(1.3px)';
    videobg.style.transform = 'scale(1.1)';
    cover.style.opacity = 1;
    inputSearch.value = '';
    this.style.width = '500px';
    this.style.color = 'rgba(0, 0, 0, 0.8)';
    inputSearch.removeEventListener('mouseleave', aa);
});


//失去焦点
var onblurs = function () {
    for (var i = 0; i < li.length; i++) {
        li[i].style.display = 'none';
    }
    ptag[0].style.visibility = 'hidden';
    ptag[1].style.visibility = 'hidden';
    this.style = '';
    tag.style.visibility = 'hidden';
    inputSearch.style.width = '250px';
    cover.style.opacity = 0;
    cover.style.zIndex = 0;
    inputSearch.style.color = ' rgba(255, 255, 255, 0.9)';
    inputSearch.addEventListener('mouseleave', aa);
    inputSearch.value = 'Search';
    //壁纸
    imgbg.style.filter = 'blur(0px)';
    imgbg.style.transform = 'scale(1)';

    //动态壁纸
    videobg.style.filter = 'blur(0px)';
    videobg.style.transform = 'scale(1)';
};
inputSearch.addEventListener('blur', function () {
    setTimeout(onblurs, 100);
});


var calendarTime = document.getElementById('calendarTime');
var timeStart = function () {
    var date = new Date();
    time.innerHTML = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':' + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
    calendarTime.innerHTML = date.getFullYear() + '年' + date.getMonth() + '月' + date.getDate() + '号' + '\t' + (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':' + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':' + (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());

};
timeStart();

setInterval(timeStart, 1000);


//获取session
var user = document.getElementById('user');


var login = document.getElementById('login');
var userInfo = document.getElementById('userInfo');
var loginMenu = document.getElementById('loginMenu');
var loginMenuIntervalS;
var loginMenuInterval;
var userInfoMsg;
loginMenu.onmouseenter = function () {
    loginMenu.style.zIndex = 999999;
    loginMenu.style.display = 'block';
    loginMenu.style.opacity = 1;
    clearInterval(loginMenuInterval);
    clearInterval(loginMenuIntervalS);
    this.style.transition = 'all .5s ease-in-out';
    this.style.transform = 'scaleY(1.05)';
};


loginMenu.onmouseleave = function () {
    this.style.transform = 'scaleY(1)';
    clearInterval(loginMenuIntervalS);
    var i = 1;
    loginMenuIntervalS = setInterval(function () {
        loginMenu.style.opacity = i;
        i = i - 0.1;
        if (i < 0) {
            clearInterval(loginMenuIntervalS);
            loginMenu.style.zIndex = 0;
            loginMenu.style.display = 'none';
        }
    }, 50);
};

user.addEventListener('mouseenter', function () {
    clearInterval(userInfoMsg);
    clearInterval(loginMenuIntervalS);
    clearInterval(loginMenuInterval);
    $.post('/user/session', '', function (data) {
        if (data == '') {
            var i = 0;
            userInfo.style.display = 'block';
            userInfo.innerHTML = '<span style="margin: 20px;font-family: 仿宋;font-weight: 900;font-size: 18px;display: inline-block;width: 200px;height: 50px">你还未登录!' +
                '<br>' +
                '<span style="font-size: 10px;color: #000000">登录后即可云端同步标便签和自定义网站URL</span>' +
                '</span>';
            userInfo.style.opacity = 1;
        } else {
            loginMenu.style.display = 'block';
            loginMenu.style.zIndex = 9999;
            loginMenu.style.opacity = 1;
        }
    });
});


user.addEventListener('mouseleave', function () {
    clearInterval(userInfoMsg);
    clearInterval(loginMenuInterval);
    var i = 1;
    userInfoMsg = setInterval(function () {
        userInfo.style.opacity = i;
        i = i - 0.1;
        if (i < 0) {
            userInfo.style.display = 'none';
            clearInterval(userInfoMsg);
        }
    }, 20);

    var is = 1;
    loginMenuInterval = setInterval(function () {
        loginMenu.style.opacity = is;
        is = is - 0.1;
        if (is < 0) {
            loginMenu.style.zIndex = 0;
            loginMenu.style.display = 'none';
            clearInterval(loginMenuInterval);
        }
    }, 20);

});


var colseLoginFlag = 0;
var colseLogin = document.getElementById('colseLogin');
colseLogin.onmouseenter = function () {
    this.style.transform = 'scale(1.2)';
    this.style.transition = 'all .55s ease-in-out';
    this.style.color = '#1d39ff';
    login.style.transition = 'all .35s ease-in-out';
    login.style.transform = 'rotateX(20deg) rotateY(15deg) translate(-50%, -50%)';

};
colseLogin.onmouseleave = function () {
    this.style.transform = 'scale(1)';
    this.style.color = 'black';
    login.style.transition = 'all .55s ease-in-out';
    login.style.transform = 'rotate(0deg) translate(-50%, -50%)';

};

colseLogin.addEventListener('click', function () {
    if (colseLoginFlag == 1) {
        login.style.opacity = 0;
        login.style.display = 'none';
        colseLoginFlag = 0;
    } else {
        login.style.opacity = 0;
        login.style.display = 'none';
        //壁纸
        imgbg.style.filter = 'blur(0px)';
        imgbg.style.transform = 'scale(1)';

        //动态壁纸
        videobg.style.filter = 'blur(0px)';
        cover.style.opacity = 0;
        cover.style.zIndex = 0;
        videobg.style.transform = 'scale(1)';
    }


});

user.addEventListener('click', function () {
    $.post('/user/session', "", function (data) {
        clearInterval(userInfoMsg);
        if (data == '') {
            login.style.opacity = 1;
            login.style.display = 'block';
            //壁纸
            imgbg.style.filter = 'blur(1.3px)';
            imgbg.style.transform = 'scale(1.1)';

            //动态壁纸
            videobg.style.filter = 'blur(1.3px)';
            videobg.style.transform = 'scale(1.1)';
            cover.style.opacity = 1;
            cover.style.zIndex = 99;
        } else {
            var i = 1;
            userInfo.style.display = 'block';
            userInfo.style.opacity = i;
            userInfo.innerHTML = '<span style="margin: 20px;">你已经是登陆状态</span>';
            userInfoMsg = setInterval(function () {
                userInfo.style.opacity = i;
                i = i - 0.1;
                if (i < 0) {
                    clearInterval(userInfoMsg);
                }
            }, 50);
        }
    });


});


var password = document.getElementById('password');
var account = document.getElementById('account');
var loginButton = document.getElementById('loginButton');
var registerButton = document.getElementById('registerButton');
var loginOut = document.getElementById('loginOut');
loginOut.onclick = function () {
    $.post('/user/loginOut', "", function (data) {
        if (data == 0) {
            alert("注销失败");
        }
        if (data == 1) {
            window.location.reload();
        }
    })
};

loginButton.onmousedown = function () {
    loginButton.style.backgroundColor = 'black';
};


loginButton.onmouseup = function () {
    loginButton.style.background = 'rgba(0, 0, 0, .55)';
};

registerButton.addEventListener('click', function () {
    if (password.value == '' || account.value == '') {
        alert('账号密码不能为空');
    } else {
        $.post('/user/register', {password: password.value, account: account.value}, function (data) {
            if (data == 1) {
                alert('注册成功、请前往登录');
            } else {
                alert('注册失败');
            }
        });

    }


});

loginButton.addEventListener('click', function () {
    $.post('/user/login', {password: password.value, account: account.value}, function (data) {
        if (data == '' || data == null) {
            alert("登陆失败！请重新登录");
        } else {
            // alert("登陆成功！ 1秒后关闭窗口");
            cover.style.zIndex = 0;
            setTimeout(function () {
                cover.style.zIndex = 0;
                login.style.opacity = 0;
                login.style.display = 'none';
                //壁纸
                imgbg.style.filter = 'blur(0px)';
                imgbg.style.transform = 'scale(1)';
                //动态壁纸
                videobg.style.filter = 'blur(0px)';
                cover.style.opacity = 0;
                videobg.style.transform = 'scale(1)';
                $.post('/memo/selectTop', '', function (data) {
                    var totalStr = '';
                    var str = '';
                    for (var i = 0; i < data.length; i++) {
                        str = '<li class="memoUpLi">\n' +
                            '            <span>' + data[i].content + '</span><br><span style="font-size: 10px;color: black">' + new Date(data[i].createTime).toLocaleString() + '</span>\n' +
                            '<input hidden value="' + data[i].createTime + '">' +
                            '        </li>';
                        totalStr += str;
                    }
                    $('#topContent').html(totalStr);
                    var memoUpLi = document.getElementsByClassName('memoUpLi');
                    for (var i = 0; i < memoUpLi.length; i++) {
                        memoUpLi[i].onclick = function () {
                            var content = this.children[0].textContent;
                            var date = this.children[3].value;
                            var ss = this;
                            $.post('/memo/noTop', {content: content, time: date}, function (data) {
                                if (data == 1) {
                                    clearInterval(memoUpLiInterval);
                                    ss.innerHTML = '被无情地取消置顶TAT~~~';
                                    var j = 1;
                                    ss.style.transform = 'rotateX(360deg)';
                                    memoUpLiInterval = setInterval(function () {
                                        ss.style.opacity = j;
                                        j = j - 0.1;
                                        if (j < 0) {
                                            ss.style.display = 'none';
                                            clearInterval(memoUpLiInterval);
                                        }
                                    }, 80);
                                } else {
                                    alert('取消置顶失败');
                                }

                            });

                        };
                    }
                    windostiao(memoUpLi);
                });

            }, 1000)
        }
    });
});


password.addEventListener('focus', function () {
    removeEventListener('keydown', windowEventListener);
});
account.addEventListener('focus', function () {
    removeEventListener('keydown', windowEventListener);
});

var addLast = document.getElementById('addLast');
var addTag = document.getElementById('addTag');

var addLastFlag = 1;
addLast.addEventListener('click', function () {
    $.post('/user/session', '', function (data) {
        if (data == '') {
            login.style.opacity = 1;
            login.style.display = 'block';
            colseLoginFlag = 1;

        } else {
            if (addLastFlag == 0) {
                addTag.style.display = 'none';
                addTag.style.opacity = 0;
                addLastFlag = 1;
                return;
            }
            if (addLastFlag == 1) {
                addTag.style.display = 'block';
                addTag.style.opacity = 1;
                addTag.style.top = (addLast.offsetTop - 120) + 'px';
                addTag.style.left = (addLast.offsetLeft + 120) + 'px';
                addLastFlag = 0;
                return;
            }
        }
    });

});

var url = document.getElementById('url');
var title = document.getElementById('title');
var addButton = document.getElementById('addButton');

addButton.onclick = function () {
    $.post('/link/addLink', {url: url.value, title: title.value}, function (data) {
        if (data == 0) {
            alert('添加失败');
            return;
        }
        if (data == 1) {
            //查询所有该用户所有链接
            /* $.post('/link/selectAllLink', '', function (data) {
                 var str = '';
                 var link = '';
                 if (data == '') {
                     str = '';
                 } else {
                     for (var i = 0; i < data.length; i++) {
                         var ranStr = (Math.random() * data[i].title.length);
                         link = '<div class="shouldNotSwitch ContextMenu">\n' +
                             '                <a href="' + data[i].url + '" target="black">\n' +
                             '                    <div style="position: absolute;width: 80px;height: 80px;background: rgba(255, 255, 255, .45);line-height: 80px;overflow:hidden;border-radius: 20px"><span style="display: inline-block;margin-top: 15px;width: 50px;height: 50px;border-radius: 255px;line-height: 50px;background: rgba(0, 0, 0, .45);color: white">' + data[i].title.substring(data[i].title.length / 2, data[i].title.length / 2 + 1) + '</span></div>\n' +
                             '                    <span class="spaniocn">' + data[i].title + '</span>\n' +
                             '                </a>\n' + '<input type="hidden" value="' + data[i].id + '">' +
                             '            </div>';
                         str += link;
                     }
                 }
                 $("#userLink").html(str);
                 var ContextMenu = document.getElementsByClassName('ContextMenu');
                 var menuCusNav = document.getElementById('menuCusNav');

                 for (var i = 0; i < ContextMenu.length; i++) {
                     ContextMenu[i].oncontextmenu = function (e) {
                         menuCusNav.style.opacity = 1;
                         menuCusNav.style.display = 'block';
                         menuCusNav.style.left = e.pageX + 'px';
                         menuCusNav.style.top = e.pageY + 'px';
                         var link = this;
                         var userMenuItem = document.getElementsByClassName('userMenuItem');
                         userMenuItem[1].onclick = function () {
                             $.post('/link/deleteId', {id: link.children[1].value}, function (data) {
                                 menuCusNav.style.opacity = 0;
                                 menuCusNav.style.display = 'none';
                             });
                         }
                     }
                 }
                 menuCusNav.onmouseleave = function () {
                     menuCusNav.style.opacity = 0;
                     menuCusNav.style.display = 'none';
                 }
             });*/
            selectAllLink();
            url.value = '';
            title.value = '';
            addTag.style.display = 'none';
            addTag.style.opacity = 0;
            addLastFlag = 1;
            return;
        }
    });
};


var writerLi = document.getElementById('writerLi');
var writerTextarea = document.getElementById('writerTextarea');
var writerIcon = document.getElementsByClassName('writerIcon');
//标签表定时器
var writerLisetInterval;
//写字板定时器
var writerTextareaInterval;
var liList = writerLi.children[0].children;
var liFlag = 1;

//保存li标签的下标到cookies
var liIndex = window.localStorage;

//给所有的li注册单击事件
for (var i = 1; i < liList.length; i++) {
    liList[i].addEventListener('click', function () {
        for (var i = 1; i < liList.length; i++) {
            liList[i].style.borderLeft = 'none';
            if (this == liList[i]) {
                liFlag = 0;
                writerTextarea.value = liList[i].children[0].innerText;
                this.style.borderLeft = '5px solid #1E90FF';
                liIndex['liIndex'] = i;
                writerTextarea.focus();

            }
        }
    })
}

liList[0].addEventListener('click', function () {
    for (var i = 1; i < liList.length; i++) {
        liList[i].style.borderLeft = 'none';
    }
    liFlag = 0;
    var li = document.createElement('li');
    var span = document.createElement('span');
    li.appendChild(span);
    var span1 = document.createElement('span');
    var timeStr = new Date().toLocaleString();
    span1.innerText = timeStr;
    li.appendChild(span1);
    li.style.borderLeft = '5px solid #1E90FF';
    writerTextarea.value = '';
    liIndex['liIndex'] = writerLi.children[0].children.length;
    writerTextarea.focus();
    writerLi.children[0].appendChild(li);
    //子节点追加时查询注册单击事件
    for (var i = 1; i < liList.length; i++) {
        liList[i].addEventListener('click', function () {
            for (var i = 1; i < liList.length; i++) {
                liList[i].style.borderLeft = 'none';
                if (this == liList[i]) {
                    liFlag = 0;
                    writerTextarea.value = liList[i].children[0].innerText;
                    this.style.borderLeft = '5px solid #1E90FF';
                    liIndex['liIndex'] = i;
                    writerTextarea.focus();
                }
            }
        })
    }


});
writerTextarea.onkeydown = function (evt) {
    if (evt.keyCode == 9) {
        if (evt.preventDefault) {
            evt.preventDefault();
        } else {
            evt.returnValue = false;
        }
    }
};
writerTextarea.onkeyup = function () {
    // 只进行一次
    if (liFlag == 1) {
        //子节点追加时查询注册单击事件
        var li = document.createElement('li');
        li.style.borderLeft = '5px solid #1E90FF';
        var span = document.createElement('span');
        li.appendChild(span);
        var span1 = document.createElement('span');
        var timeStr = new Date().toLocaleString();
        span1.innerText = timeStr;
        li.appendChild(span1);
        writerLi.children[0].appendChild(li);
        for (var i = 1; i < liList.length; i++) {
            liList[i].addEventListener('click', function () {
                for (var i = 1; i < liList.length; i++) {
                    liList[i].style.borderLeft = 'none';
                    if (this == liList[i]) {
                        liFlag = 0;
                        writerTextarea.value = liList[i].children[0].innerText;
                        this.style.borderLeft = '5px solid #1E90FF';
                        liIndex['liIndex'] = i;
                        writerTextarea.focus();
                    }
                }
            })
        }
        liFlag = 0;
        liIndex['liIndex'] = liList.length - 1;
    }
    writerLi.children[0].children[liIndex.liIndex].children[0].innerHTML = writerTextarea.value;
};

writerLi.onmouseover = function () {
    writerTextarea.onblur = null;
    writerTextarea.onfocus = null;
};
var writerTextareaOnfocus = function () {
    clearInterval(writerTextareaInterval);
    clearInterval(writerLisetInterval);
    window.removeEventListener('keydown', windowEventListener);
    var i = 0;
    writerLisetInterval = setInterval(function () {
        writerLi.style.left = (writerLi.offsetLeft - 1) + 'px';
        writerLi.style.opacity = i;
        i = i + 0.02;
        if (writerLi.offsetLeft == -60) {
            for (var j = 0; j < writerIcon.length; j++) {
                writerIcon[j].style.display = 'block';
            }
            clearInterval(writerLisetInterval);
        }
    }, 5);
    writerTextareaInterval = setInterval(function () {
        writerTextarea.style.left = (writerTextarea.offsetLeft + 2) + 'px';
        if (writerTextarea.offsetLeft == 200) {
            clearInterval(writerTextareaInterval);
        }
    }, 1);
};
writerTextarea.onfocus = writerTextareaOnfocus;
var writerTextareaOnblur = function () {
    clearInterval(writerLisetInterval);
    clearInterval(writerTextareaInterval);
    for (var j = 0; j < writerIcon.length; j++) {
        writerIcon[j].style.display = 'none';
    }
    var i = 1;
    writerLisetInterval = setInterval(function () {
        writerLi.style.left = (writerLi.offsetLeft + 1) + 'px';
        writerLi.style.opacity = i;
        i = i - 0.02;
        if (writerLi.offsetLeft == 0) {
            clearInterval(writerLisetInterval);
        }
    }, 5);
    writerTextareaInterval = setInterval(function () {
        writerTextarea.style.left = (writerTextarea.offsetLeft - 2) + 'px';
        if (writerTextarea.offsetLeft == 0) {
            clearInterval(writerTextareaInterval);
        }
    }, 1);
};
writerTextarea.onblur = setTimeout(writerTextareaOnblur(), 100);


//标签按钮
var writerBq = document.getElementById('writerBq');
var writerBox = document.getElementById('writerBox');
var writerBoxInterval;
writerBq.onclick = function () {
    $.post("/memo/selectMemoAll", "", function (data) {
        var str = '';
        var totalStr = ' <li>＋新便笺</li>';
        for (var i = 0; i < data.length; i++) {
            str = '<li>\n' +
                '                <span>' + data[i].content + '</span>\n' +
                '                <span>' + new Date(data[i].createTime).toLocaleString() + '' +
                '<input hidden value="' + data[i].createTime + '">' +
                '</span>\n' +
                '            </li>';

            totalStr += str;
        }
        $('#userMemo').html(totalStr);
        liList[0].addEventListener('click', function () {
            for (var i = 1; i < liList.length; i++) {
                liList[i].style.borderLeft = 'none';
            }
            liFlag = 0;
            var li = document.createElement('li');
            var span = document.createElement('span');
            li.appendChild(span);
            var span1 = document.createElement('span');
            var timeStr = new Date().toLocaleString();
            span1.innerText = timeStr;
            li.appendChild(span1);
            li.style.borderLeft = '5px solid #1E90FF';
            writerTextarea.value = '';
            liIndex['liIndex'] = writerLi.children[0].children.length;
            writerTextarea.focus();
            writerLi.children[0].appendChild(li);

            //子节点追加时查询注册单击事件
            for (var i = 1; i < liList.length; i++) {
                liList[i].addEventListener('click', function () {
                    for (var i = 1; i < liList.length; i++) {
                        liList[i].style.borderLeft = 'none';
                        if (this == liList[i]) {
                            liFlag = 0;
                            writerTextarea.value = liList[i].children[0].innerText;
                            this.style.borderLeft = '5px solid #1E90FF';
                            liIndex['liIndex'] = i;
                            writerTextarea.focus();
                        }
                    }
                })
            }


        });
        for (var i = 1; i < liList.length; i++) {
            liList[i].addEventListener('click', function () {
                for (var i = 1; i < liList.length; i++) {
                    liList[i].style.borderLeft = 'none';
                    if (this == liList[i]) {
                        liFlag = 0;
                        writerTextarea.value = liList[i].children[0].innerText;
                        this.style.borderLeft = '5px solid #1E90FF';
                        liIndex['liIndex'] = i;
                        writerTextarea.focus();
                    }
                }
            })
        }
    });
    writerLi.style.opacity = 1;
    clearInterval(writerBoxInterval);
    var i = 0;
    writerBox.style.display = 'block';
    writerBox.style.zIndex = 9999;
    writerBoxInterval = setInterval(function () {
        writerBox.style.opacity = i;
        i = i + 0.1;
        if (i > 1) {
            clearInterval(writerBoxInterval);
        }
    }, 20);

    cover.style.opacity = 1;
    cover.style.zIndex = 99;
    //壁纸
    imgbg.style.filter = 'blur(1.3px)';

    imgbg.style.transform = 'scale(1.1)';
    //动态壁纸
    videobg.style.filter = 'blur(1.3px)';
    videobg.style.transform = 'scale(1.1)';
    liFlag = 1;
    writerTextarea.value = '';
    writerTextarea.focus();
};

writerIcon[2].addEventListener('click', function () {
    // writerTextarea.focus();
    if (writerTextarea.value == '') {
        alert('请填写好你的便笺~再保存吧');
        // writerTextarea.onfocus = null;
        return;
    } else {
        $.post('/memo/insert', {content: writerTextarea.value}, function (data) {
            if (data == 0) {
                alert("添加失败");
            }
            if (data == 1) {
                alert("添加成功");
                $.post("/memo/selectMemoAll", "", function (data) {
                    var str = '';
                    var totalStr = ' <li>＋新便笺</li>';
                    for (var i = 0; i < data.length; i++) {
                        str = '<li>\n' +
                            '                <span>' + data[i].content + '</span>\n' +
                            '                <span>' + new Date(data[i].createTime).toLocaleString() + '' +
                            '<input hidden value="' + data[i].createTime + '">' +
                            '</span>\n' +
                            '            </li>';
                        totalStr += str;
                    }
                    $('#userMemo').html(totalStr);
                    liList[liIndex.liIndex].style.borderLeft = '5px solid #1E90FF';
                    writerTextarea.onfocus = null;
                    liList[0].addEventListener('click', function () {
                        for (var i = 1; i < liList.length; i++) {
                            liList[i].style.borderLeft = 'none';
                        }
                        liFlag = 0;
                        var li = document.createElement('li');
                        var span = document.createElement('span');
                        li.appendChild(span);
                        var span1 = document.createElement('span');
                        var timeStr = new Date().toLocaleString();
                        span1.innerText = timeStr;
                        li.appendChild(span1);
                        li.style.borderLeft = '5px solid #1E90FF';
                        writerTextarea.value = '';
                        liIndex['liIndex'] = writerLi.children[0].children.length;
                        writerTextarea.focus();
                        writerLi.children[0].appendChild(li);
                        //子节点追加时查询注册单击事件
                        for (var i = 1; i < liList.length; i++) {
                            liList[i].addEventListener('click', function () {
                                for (var i = 1; i < liList.length; i++) {
                                    liList[i].style.borderLeft = 'none';
                                    if (this == liList[i]) {
                                        liFlag = 0;
                                        writerTextarea.value = liList[i].children[0].innerText;
                                        this.style.borderLeft = '5px solid #1E90FF';
                                        liIndex['liIndex'] = i;
                                        writerTextarea.focus();
                                    }
                                }
                            })
                        }
                    });
                    for (var i = 1; i < liList.length; i++) {
                        liList[i].addEventListener('click', function () {
                            for (var i = 1; i < liList.length; i++) {
                                liList[i].style.borderLeft = 'none';
                                if (this == liList[i]) {
                                    liFlag = 0;
                                    writerTextarea.value = liList[i].children[0].innerText;
                                    this.style.borderLeft = '5px solid #1E90FF';
                                    liIndex['liIndex'] = i;
                                    writerTextarea.focus();
                                }
                            }
                        })
                    }
                });
            }
        });
    }
});

var memoUpLiInterval;

//删除
writerIcon[0].addEventListener('click', function () {
    var flag = confirm('你真的要删除这条便笺吗');
    if (flag) {
        var content = userMemo.children[liIndex.liIndex].children[0].textContent;
        var date = userMemo.children[liIndex.liIndex].children[1].children[0].value;
        $.post('/memo/delete', {content: content, time: date}, function (data) {
            if (data == 1) {
                $.post("/memo/selectMemoAll", "", function (data) {
                    var str = '';
                    var totalStr = ' <li>＋新便笺</li>';
                    for (var i = 0; i < data.length; i++) {
                        str = '<li>\n' +
                            '                <span>' + data[i].content + '</span>\n' +
                            '                <span>' + new Date(data[i].createTime).toLocaleString() + '' +
                            '<input hidden value="' + data[i].createTime + '">' +
                            '</span>\n' +
                            '            </li>';

                        totalStr += str;
                    }
                    $('#userMemo').html(totalStr);
                    liList[0].addEventListener('click', function () {
                        for (var i = 1; i < liList.length; i++) {
                            liList[i].style.borderLeft = 'none';
                        }
                        liFlag = 0;
                        var li = document.createElement('li');
                        var span = document.createElement('span');
                        li.appendChild(span);
                        var span1 = document.createElement('span');
                        var timeStr = new Date().toLocaleString();
                        span1.innerText = timeStr;
                        li.appendChild(span1);
                        li.style.borderLeft = '5px solid #1E90FF';
                        writerTextarea.value = '';
                        liIndex['liIndex'] = writerLi.children[0].children.length;
                        writerTextarea.focus();
                        writerLi.children[0].appendChild(li);
                        //子节点追加时查询注册单击事件
                        for (var i = 1; i < liList.length; i++) {
                            liList[i].addEventListener('click', function () {
                                for (var i = 1; i < liList.length; i++) {
                                    liList[i].style.borderLeft = 'none';
                                    if (this == liList[i]) {
                                        liFlag = 0;
                                        writerTextarea.value = liList[i].children[0].innerText;
                                        this.style.borderLeft = '5px solid #1E90FF';
                                        liIndex['liIndex'] = i;
                                        writerTextarea.focus();
                                    }
                                }
                            })
                        }
                    });
                    for (var i = 1; i < liList.length; i++) {
                        liList[i].addEventListener('click', function () {
                            for (var i = 1; i < liList.length; i++) {
                                liList[i].style.borderLeft = 'none';
                                if (this == liList[i]) {
                                    liFlag = 0;
                                    writerTextarea.value = liList[i].children[0].innerText;
                                    this.style.borderLeft = '5px solid #1E90FF';
                                    liIndex['liIndex'] = i;
                                    writerTextarea.focus();
                                }
                            }
                        })
                    }
                });
                $.post('/memo/selectTop', '', function (data) {
                    var totalStr = '';
                    var str = '';
                    for (var i = 0; i < data.length; i++) {
                        str = '<li class="memoUpLi">\n' +
                            '            <span>' + data[i].content + '</span><br><span style="font-size: 10px;color: black">' + new Date(data[i].createTime).toLocaleString() + '</span>\n' +
                            '<input hidden value="' + data[i].createTime + '">' +
                            '        </li>';
                        totalStr += str;
                    }
                    $('#topContent').html(totalStr);
                    var memoUpLi = document.getElementsByClassName('memoUpLi');
                    for (var i = 0; i < memoUpLi.length; i++) {
                        memoUpLi[i].onclick = function () {
                            var content = this.children[0].textContent;
                            var date = this.children[3].value;
                            var ss = this;
                            $.post('/memo/noTop', {content: content, time: date}, function (data) {
                                if (data == 1) {
                                    clearInterval(memoUpLiInterval);
                                    ss.innerHTML = '被无情地取消置顶TAT~~~';
                                    var j = 1;
                                    ss.style.transform = 'rotateX(360deg)';
                                    memoUpLiInterval = setInterval(function () {
                                        ss.style.opacity = j;
                                        j = j - 0.1;
                                        if (j < 0) {
                                            ss.style.display = 'none';
                                            clearInterval(memoUpLiInterval);
                                        }
                                    }, 80);
                                } else {
                                    alert('取消置顶失败');
                                }

                            });

                        };
                    }
                    windostiao(memoUpLi);
                });

            }
            if (date == 0) {
                alert('删除失败');
            }
        });
    }
});

//置顶
var memoUpLiInterval;
$.post('/user/session', '', function (data) {
    if (data != '') {
        $.post('/memo/selectTop', '', function (data) {
            var totalStr = '';
            var str = '';
            for (var i = 0; i < data.length; i++) {
                str = '<li class="memoUpLi">\n' +
                    '            <span>' + data[i].content + '</span><br><span style="font-size: 10px;color: black">' + new Date(data[i].createTime).toLocaleString() + '</span>\n' +
                    '<input hidden value="' + data[i].createTime + '">' +
                    '        </li>';
                totalStr += str;
            }
            $('#topContent').html(totalStr);
            var memoUpLi = document.getElementsByClassName('memoUpLi');
            for (var i = 0; i < memoUpLi.length; i++) {
                memoUpLi[i].onclick = function () {
                    var content = this.children[0].textContent;
                    var date = this.children[3].value;
                    var ss = this;
                    $.post('/memo/noTop', {content: content, time: date}, function (data) {
                        if (data == 1) {
                            clearInterval(memoUpLiInterval);
                            ss.innerHTML = '被无情地取消置顶TAT~~~';
                            var j = 1;
                            ss.style.transform = 'rotateX(360deg)';
                            memoUpLiInterval = setInterval(function () {
                                ss.style.opacity = j;
                                j = j - 0.1;
                                if (j < 0) {
                                    ss.style.display = 'none';
                                    clearInterval(memoUpLiInterval);
                                }
                            }, 80);
                        } else {
                            alert('取消置顶失败');
                        }

                    });

                };
            }
            windostiao(memoUpLi);
        });
    }
});

//后端实现
writerIcon[1].addEventListener('click', function () {
    var content = userMemo.children[liIndex.liIndex].children[0].textContent;
    var date = userMemo.children[liIndex.liIndex].children[1].children[0].value;
    $.post('/memo/top', {content: content, time: date}, function (data) {
        if (data == 2) {
            alert('最多4条置顶');
        }
        if (data == 1) {
            $.post('/memo/selectTop', '', function (data) {
                var totalStr = '';
                var str = '';
                for (var i = 0; i < data.length; i++) {
                    str = '<li class="memoUpLi">\n' +
                        '            <span>' + data[i].content + '</span><br><span style="font-size: 10px;color: black">' + new Date(data[i].createTime).toLocaleString() + '</span>' +
                        '<input hidden value="' + data[i].createTime + '">\n' +
                        '        </li>';
                    totalStr += str;
                }
                $('#topContent').html(totalStr);
                var memoUpLi = document.getElementsByClassName('memoUpLi');
                for (var i = 0; i < memoUpLi.length; i++) {
                    memoUpLi[i].onclick = function () {
                        var content = this.children[0].textContent;
                        var date = this.children[3].value;
                        var ss = this;
                        $.post('/memo/noTop', {content: content, time: date}, function (data) {
                            if (data == 1) {
                                clearInterval(memoUpLiInterval);
                                ss.innerHTML = '被无情地取消置顶TAT~~~';
                                var j = 1;
                                ss.style.transform = 'rotateX(360deg)';
                                memoUpLiInterval = setInterval(function () {
                                    ss.style.opacity = j;
                                    j = j - 0.1;
                                    if (j < 0) {
                                        ss.style.display = 'none';
                                        clearInterval(memoUpLiInterval);
                                    }
                                }, 80);
                            } else {
                                alert('取消置顶失败');
                            }

                        });

                    };
                }
                windostiao(memoUpLi);

            });
        }
        if (data == 0) {
            alert('置顶失败');
        }
        if (data == 3) {
            alert('已经置顶');
        }

    });
});


var userManage = document.getElementById('userManage');
var userManager = document.getElementById('userManager');
var userManagerColse = document.getElementById('userManagerColse');

userManage.onclick = function () {
    userManager.style.display = 'block';
    userManager.style.opacity = 1;
    userManager.style.zIndex = 9999;
    cover.style.opacity = 1;
    cover.style.zIndex = 9998;
    cover.onclick = null;
    window.removeEventListener('keydown', windowEventListener);
};

userManagerColse.onmouseenter = function () {
    this.style.transform = 'scale(1.2)';
    this.style.transition = 'all .55s ease-in-out';
    this.style.color = '#1d39ff';
    userManager.style.transition = 'all .35s ease-in-out';
    userManager.style.transform = 'rotateX(20deg) rotateY(15deg)';

};
userManagerColse.onmouseleave = function () {
    this.style.transform = 'scale(1)';
    this.style.color = 'black';
    userManager.style.transition = 'all .55s ease-in-out';
    userManager.style.transform = 'rotate(0deg)';

};

userManagerColse.onclick = function () {
    userManager.style.display = 'none';
    userManager.style.opacity = 0;
    userManager.style.zIndex = 0;
    cover.style.opacity = 0;
    cover.style.zIndex = 0;
    window.addEventListener('keydown', windowEventListener);
    cover.onclick = coverFuntion;
};


function windostiao(obj) {
    for (var i = 0; i < obj.length; i++) {
        obj[i].addEventListener('mousemove', function (e) {
            this.style.transition = 'all .25s ease-in-out';
            if ((e.clientX - this.offsetLeft) <= (this.offsetWidth / 2) && (e.clientY - this.offsetTop) < (this.offsetHeight / 2)) {
                this.style.transform = 'rotateX(20deg) rotateY(-15deg)';
            }
            if ((e.clientX - this.offsetLeft) <= (this.offsetWidth / 2) && (e.clientY - this.offsetTop) >= (this.offsetHeight / 2)) {
                this.style.transform = 'rotateX(-20deg) rotateY(-15deg)';
            }
            if ((e.clientX - this.offsetLeft) > (this.offsetWidth / 2) && (e.clientY - this.offsetTop) > (this.offsetHeight / 2)) {
                this.style.transform = 'rotateX(-20deg) rotateY(15deg)';
            }
            if ((e.clientX - this.offsetLeft) >= (this.offsetWidth / 2) && (e.clientY - this.offsetTop) <= (this.offsetHeight / 2)) {
                this.style.transform = 'rotateX(20deg) rotateY(15deg)';
            }
        });
        obj[i].addEventListener('mouseleave', function (e) {
            this.style.transition = 'all .25s ease-in-out';
            this.style.transform = 'rotate(0deg)';
        })
    }
}

$.get('https://v1.hitokoto.cn/?c=d&c=i&encode=json', '', function (data) {
    console.log(data);
    ptag[0].innerHTML = '「&nbsp;&nbsp;' + data.hitokoto + '」';
    ptag[1].innerHTML = '——' + data.from;
});